package com.swz.dcrm.widget;

import android.content.Context;
import android.widget.TextView;

import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.utils.MPPointF;
import com.swz.dcrm.R;
import com.swz.dcrm.util.DateUtils;
import com.swz.dcrm.util.Tool;

import java.util.List;

public class MyMarkerView extends MarkerView {
    private TextView tvDate;
    private TextView tvCount;

    private List<String> xValue;
    /**
     * Constructor. Sets up the MarkerView with a custom layout resource.
     *
     * @param context
     */
    public MyMarkerView(Context context, List<String> xValue) {
        super(context, R.layout.markerview);

        this.xValue=xValue;
        tvDate=findViewById(R.id.tv_date);
        tvCount=findViewById(R.id.tv_count);

    }

    @Override
    public void refreshContent(Entry e, Highlight highlight) {

        /*Chart chart = getChartView();
        if (chart instanceof LineChart) {
            LineData lineData = ((LineChart) chart).getLineData();
            //获取到图表中的所有曲线
            List<ILineDataSet> dataSetList = lineData.getDataSets();
            for (int i = 0; i < dataSetList.size(); i++) {
                LineDataSet dataSet = (LineDataSet) dataSetList.get(i);
                //获取到曲线的所有在Y轴的数据集合，根据当前X轴的位置 来获取对应的Y轴值
                float y = dataSet.getValues().get((int) e.getX()).getY();

            }*/



        tvDate.setText("日期:"+ DateUtils.dateFormat(xValue.get((int) e.getX()),"yyyy年M月d日"));
        tvCount.setText("数量:"+(int)e.getY());

        super.refreshContent(e, highlight);
    }

    @Override
    public MPPointF getOffset() {

        return new MPPointF(50, -getHeight()/2);
    }

}
